import { INCREMENT, DECREMENT } from '../const.js'

const initState = {
    num: 0
}

function counterReducer(state = initState, action) {
    const { type, payload } = action;
    const newState = Object.assign({}, state);
    switch (type) {
        case INCREMENT:
            newState.num = newState.num + payload;
            break;
        case DECREMENT:
        	newState.num = newState.num - payload;
            break;
        default:
            break;
    }
    return newState;
}

export default counterReducer